<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Format a currency value</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="numberformatter.create.html">« NumberFormatter::create</a></li>
      <li style="float: right;"><a href="numberformatter.format.html">NumberFormatter::format »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.numberformatter.html">NumberFormatter</a></li>
    <li>Format a currency value</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="numberformatter.formatcurrency" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">NumberFormatter::formatCurrency</h1>
  <h1 class="refname">numfmt_format_currency</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">NumberFormatter::formatCurrency</span> -- <span class="refname">numfmt_format_currency</span> &mdash; <span class="dc-title">Format a currency value</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-numberformatter.formatcurrency-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>NumberFormatter::formatCurrency</strong></span>(<span class="methodparam"><span class="type">float</span> <code class="parameter">$amount</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$currency</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>numfmt_format_currency</strong></span>(<span class="methodparam"><span class="type"><a href="class.numberformatter.html" class="type NumberFormatter">NumberFormatter</a></span> <code class="parameter">$formatter</code></span>, <span class="methodparam"><span class="type">float</span> <code class="parameter">$amount</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$currency</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Format the currency value according to the formatter rules.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-numberformatter.formatcurrency-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">formatter</code></dt>

     <dd>

      <p class="para">
       <span class="classname"><a href="class.numberformatter.html" class="classname">NumberFormatter</a></span> object.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">amount</code></dt>

     <dd>

      <p class="para">
       The numeric currency value.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">currency</code></dt>

     <dd>

      <p class="para">
       The 3-letter ISO 4217 currency code indicating the currency to use.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>



 <div class="refsect1 returnvalues" id="refsect1-numberformatter.formatcurrency-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   String representing the formatted currency value,  或者在失败时返回 <strong><code>false</code></strong>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-numberformatter.formatcurrency-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2298">
   <p><strong>示例 #1 <span class="function"><strong>numfmt_format_currency()</strong></span> example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">numfmt_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">CURRENCY&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">numfmt_format_currency</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">numfmt_format_currency</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">numfmt_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'ru_RU'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">CURRENCY&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">numfmt_format_currency</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">numfmt_format_currency</span><span style="color: #007700">(</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <div class="example" id="example-2299">
   <p><strong>示例 #2 OO example</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'de_DE'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">CURRENCY&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">formatCurrency</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">formatCurrency</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fmt&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'ru_RU'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">NumberFormatter</span><span style="color: #007700">::</span><span style="color: #0000BB">CURRENCY&nbsp;</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">formatCurrency</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo&nbsp;</span><span style="color: #0000BB">$fmt</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">formatCurrency</span><span style="color: #007700">(</span><span style="color: #0000BB">1234567.891234567890000</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RUR"</span><span style="color: #007700">).</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
1.234.567,89 €
1.234.567,89 RUR
1 234 567,89€
1 234 567,89р.
</pre></div>
  </div>
 </div>


 <div class="refsect1 notes" id="refsect1-numberformatter.formatcurrency-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="para">
    Formats achievable by this method of formatting cannot fully use the possibilities of underlying ICU library,
    such as to format currency with narrow currency symbol.
   </p>
   <p class="para">
    To fully utilize them use <span class="function"><a href="messageformatter.formatmessage.html" class="function">msgfmt_format_message()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-numberformatter.formatcurrency-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="numberformatter.geterrorcode.html" class="function" rel="rdfs-seeAlso">numfmt_get_error_code()</a> - Get formatter's last error code</span></li>
    <li class="member"><span class="function"><a href="numberformatter.format.html" class="function" rel="rdfs-seeAlso">numfmt_format()</a> - Format a number</span></li>
    <li class="member"><span class="function"><a href="numberformatter.parsecurrency.html" class="function" rel="rdfs-seeAlso">numfmt_parse_currency()</a> - Parse a currency number</span></li>
    <li class="member"><span class="function"><a href="messageformatter.formatmessage.html" class="function" rel="rdfs-seeAlso">msgfmt_format_message()</a> - Quick format message</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>